home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / vfft / realvfft.cxx < prev    next >
Encoding:
Text File  |  1992-03-12  |  4.8 KB  |  169 lines

  1. /* realvfft.cxx
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3.  
  4. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  5. Permission is granted to reproduce this software for non-commercial
  6. purposes provided that this notice is left intact.
  7.  
  8. It is acknowledged that the U.S. Government has rights to this software
  9. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  10. and the University of California.
  11.  
  12. This software is provided as a professional and academic contribution
  13. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  14. with no warranties of any kind whatsoever, no support, no promise of
  15. updates, or printed documentation. By using this software, you
  16. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  17. University of California shall have no liability with respect to the
  18. infringement of other copyrights by any part of this software.
  19.  
  20. For further information about this notice, contact William Johnston,
  21. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  22. (wejohnston@lbl.gov)
  23.  
  24. For further information about this software, contact:
  25.     Jin Guojun
  26.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  27.     g_jin@lbl.gov
  28.  
  29. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  30. */
  31.  
  32. dimen2size = dimen1len * row << 1; /* use non complex represent complex size */
  33.  
  34. if (dflag)    {
  35. double    *itemp,
  36.     *ibuf = nzalloc(fsize, sizeof(*ibuf), "fibuf"),
  37.     *obuf = nzalloc(dimen2size*(dimens?1:frm), sizeof(*obuf), "fobuf");
  38.  
  39.     uimg.o_form = dimens ? IFMT_DVFFT2D : IFMT_DVFFT3D;
  40.     uimg.pxl_out = 16;
  41.     (*uimg.header_handle)(HEADER_WRITE, &uimg, argc, argv, True);
  42.  
  43.     if (uimg.pxl_in < sizeof(*itemp))
  44.         itemp = nzalloc(fsize, uimg.pxl_in, "itemp");
  45.     else    itemp = ibuf;
  46.  
  47.     DBwork_space_init(MAX(MAX(cln, row), frm));
  48.  
  49.     for (f=0; f<frm; f++){
  50.         i = upread(itemp, uimg.pxl_in, fsize, stdin);
  51.         if (i != fsize)
  52.         syserr("frame %d [%ld] read %d", f, fsize, i);
  53.         if (uimg.in_form != IFMT_DOUBLE){
  54.         switch(uimg.in_form){
  55.         case IFMT_BYTE:    btod(itemp, ibuf, fsize);
  56.             break;
  57.         case IFMT_SHORT:    stod(itemp, ibuf, fsize);
  58.             break;
  59.         case IFMT_LONG:    itod(itemp, ibuf, fsize);
  60.             break;
  61.         case IFMT_FLOAT:    ftod(itemp, ibuf, fsize);
  62.         }
  63.         }
  64.  
  65.         DBvfft2d(ibuf, cln, row, obuf + (dimens ? 0 : f*dimen2size));
  66.  
  67.         if (dimens){
  68.         i = fwrite(obuf, sizeof(*obuf), dimen2size, out_fp);
  69.         if (i != dimen2size)
  70.             syserr("2d[%d] write %d", dimen2size, i);
  71.         }
  72.     }
  73.     if (!dimens && frm>1){
  74.     int    r;
  75.     DBCOMPLEX    *cp;
  76.     register DBCOMPLEX    *cmptr;
  77.     register int    c, n=frm, dimen1size = dimen1len;
  78.  
  79.         load_DBw(frm);
  80.  
  81.         for (r=0; r<row; r++)
  82.             for (c=0; c<dimen1size; c++){
  83.             cp = (DBCOMPLEX*)obuf + r*dimen1size + c;
  84.             cmptr = DBcmpx_in;
  85.             for (i = 0; i < n; i++, cp+=dimen2size>>1)
  86.                 cmptr[i] = *cp;
  87.  
  88.             DBFourier(cmptr, n, DBcmpx_out);
  89.  
  90.             cp = (DBCOMPLEX*)obuf + r*dimen1size + c;/* store back to dst */
  91.             cmptr = DBcmpx_out;
  92.             for (i = 0; i < n; i++, cp+=dimen2size>>1)
  93.                 *cp = cmptr[i];
  94.             }
  95.     /*    row = dimen1size;    real columns for IFMT_COMPLEX */
  96.         fsize = frm*dimen2size;
  97.         i = fwrite(obuf, sizeof(*obuf), fsize, out_fp);
  98.         if (i != fsize)
  99.             syserr("3d[%d] write %d", fsize, i);
  100.     }
  101. }
  102. else    {
  103. float    *itemp,
  104.     *ibuf = nzalloc(fsize, sizeof(*ibuf), "fibuf"),
  105.     *obuf = nzalloc(dimen2size*(dimens?1:frm), sizeof(*obuf), "fobuf");
  106.  
  107.     uimg.o_form = dimens ? IFMT_VFFT2D : IFMT_VFFT3D;
  108.     uimg.pxl_out = 8;
  109.     (*uimg.header_handle)(HEADER_WRITE, &uimg, argc, argv, True);
  110.  
  111.     if (uimg.pxl_in < sizeof(*itemp))
  112.         itemp = nzalloc(fsize, uimg.pxl_in, "itemp");
  113.     else    itemp = ibuf;
  114.  
  115.     work_space_init(MAX(MAX(cln, row), frm));
  116.  
  117.     for (f=0; f<frm; f++)    {
  118.         i = upread(itemp, uimg.pxl_in, fsize, stdin);
  119.         if (i != fsize)
  120.         syserr("frame %d [%ld] read %d", f, fsize, i);
  121.         if (uimg.in_form != IFMT_FLOAT){
  122.         switch (uimg.in_form)    {
  123.         case IFMT_BYTE:    btof(itemp, ibuf, fsize);
  124.             break;
  125.         case IFMT_SHORT:    stof(itemp, ibuf, fsize);
  126.             break;
  127.         case IFMT_LONG:    itof(itemp, ibuf, fsize);
  128.             break;
  129.         }
  130.         }
  131.  
  132.         vfft2d(ibuf, cln, row, obuf + (dimens ? 0 : f*dimen2size));
  133.  
  134.         if (dimens){
  135.         i = fwrite(obuf, sizeof(*obuf), dimen2size, out_fp);
  136.         if (i != dimen2size)
  137.             syserr("2d[%d] write %d", dimen2size, i);
  138.         }
  139.     }
  140.     if (!dimens && frm>1){
  141.     int    r;
  142.     COMPLEX    *cp;
  143.     register COMPLEX    *cmptr;
  144.     register int    c, n=frm, dimen1size = dimen1len;
  145.  
  146.         load_w(frm);
  147.  
  148.         for (r=0; r<row; r++)
  149.             for (c=0; c<dimen1size; c++){
  150.             cp = (COMPLEX*)obuf + r*dimen1size + c;
  151.             cmptr = cmpx_in;
  152.             for (i = 0; i < n; i++, cp+=dimen2size>>1)
  153.                 cmptr[i] = *cp;
  154.  
  155.             Fourier(cmptr, n, cmpx_out);
  156.  
  157.             cp = (COMPLEX*)obuf + r*dimen1size + c;/* store back to dst */
  158.             cmptr = cmpx_out;
  159.             for (i = 0; i < n; i++, cp+=dimen2size>>1)
  160.                 *cp = cmptr[i];
  161.             }
  162.     /*    row = dimen1size;    real columns for IFMT_COMPLEX */
  163.         fsize = frm*dimen2size;
  164.         i = fwrite(obuf, sizeof(*obuf), fsize, out_fp);
  165.         if (i != fsize)
  166.             syserr("3d[%d] write %d", fsize, i);
  167.     }
  168. }
  169.